﻿
@{
    Layout = null;

}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="~/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/Content/style.css" />
    <link href="~/assets/css/codemirror.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/assets/css/ace.min.css" />
    <link rel="stylesheet" href="~/font/css/font-awesome.min.css" />
    <link rel="stylesheet" href="~/layui/css/layui.css" />
    <!--[if lte IE 8]>
      <link rel="stylesheet" href="~/assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="~/Scripts/jquery-1.9.1.min.js"></script>
    <script src="~/layui/layui.js" type="text/javascript"></script>
    <script src="~/assets/js/bootstrap.min.js"></script>
    <script src="~/assets/js/typeahead-bs2.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="~/assets/layer/layer.js" type="text/javascript"></script>
    <script src="~/assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="~/Timejs/Time.js"></script>
    <title>管理权限</title>
</head>

<body>
    <div class="margin clearfix">
        <div class="border clearfix">

            <span class="l_f">
                <a href="javascript:ovid()" id="Competence_add" class="btn btn-warning" title="添加菜单"><i class="fa fa-plus"></i> 添加菜单</a>
                
            </span>
            <span class="r_f">共：<b>5</b>类</span>
        </div>
        <div class="compete_list">
            <table class="layui-hide" id="test" lay-filter="demo"></table>
            <script id="barDemo" type="text/html">
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
            <script type="text/html" id="switchTpl">
                <input type="checkbox" id="{{d.Id}}" name="Status" value="{{d.IsShow}}" lay-skin="switch" lay-text="是|否" lay-filter="sexDemo1" {{ d.IsShow == '1' ? 'checked' : '' }}={{ d.IsShow == '1' ? 'checked' : '' }} />
            </script>
        </div>
    </div>

    <!--添加权限样式-->
    <div id="Competence_add_style" style="display:none">
        <div class="Competence_add_style">
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="form-field-1">组ID</label>
                <div class="col-sm-9"><input type="text" id="ModuleId" placeholder="" name="组ID" class="col-xs-10 col-sm-5" /></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 父级菜单ID </label>
                <div class="col-sm-9"><input type="text" id="ParentId" placeholder="" name="父级菜单ID" class="col-xs-10 col-sm-5" /></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 名称 </label>
                <div class="col-sm-9"><input type="text" id="Name" placeholder="" name="名称" class="col-xs-10 col-sm-5" /></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单地址 </label>
                <div class="col-sm-9"><input type="text" id="Url" placeholder="" name="菜单地址" class="col-xs-10 col-sm-5" /></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单图标 </label>
                <div class="col-sm-9"><input type="text" id="Icon" placeholder="" name="菜单图标" class="col-xs-10 col-sm-5" /></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 排序Id </label>
                <div class="col-sm-9"><input type="text" id="SortId" placeholder="" name="排序Id" class="col-xs-10 col-sm-5" /></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 创建人 </label>
                <div class="col-sm-9"><input type="text" id="CreateUserId" placeholder="" name="创建人" class="col-xs-10 col-sm-5" /></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 创建时间 </label>
                <div class="col-sm-9"><input type="text" id="CreateTime" placeholder="" name="创建时间" class="col-xs-10 col-sm-5" /></div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right">是否显示</label>
                <div class="col-sm-9">
                    <select lay-verify="required" name="IsShow" id="IsShow">
                        <option value="0">隐藏</option>
                        <option value="1">显示</option>
                    </select>
                </div>
            </div>
            <input type="hidden" id="ID" value="" />
        </div>
    </div>
</body>
</html>
<script>
    layui.use('table', function () {
        var table = layui.table
        , form = layui.form;  //启用
        table.render({
            elem: '#test'
            , url: '/Menu/GetModulePageList/'
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[
                { type: 'checkbox' }
                , { field: 'Id', width: 180, align: 'center', title: 'Id', sort: true }
                , { field: 'ModuleId', width: 180, align: 'center', title: '组ID' }
                , { field: 'ParentId', width: 180, align: 'center', title: '父级菜单ID', sort: true }
                , { field: 'Name', width: 180, align: 'center', title: '名称' }
                , { field: 'Url', width: 180, align: 'center', title: '菜单地址' }
                , { field: 'IsShow', width: 180, align: 'center', title: '是否显示',templet: '#switchTpl', unresize: true }
                , { field: 'Icon', width: 180, align: 'center', title: '菜单图标' }
                , { field: 'SortId', width: 180, align: 'center', title: '排序Id' }
                , { field: 'CreateUserId', width: 180, align: 'center', title: '创建人' }
                , { field: 'CreateTime', width: 180, align: 'center', title: '创建时间', templet: "<div>{{Format(d.CreateTime,'yyyy-MM-dd')}}</div>" }
                , { fixed: 'right', title: '操作', width: 208, align: 'center', toolbar: '#barDemo' }
            ]]
            , page: true
            , id: 'testReload'
        });
        //显示(开启|关闭)
        form.on('switch(sexDemo1)', function (obj) {

            var tip = "开启";
            var datas = {};
            datas.Id = this.id;
            datas.IsShow = this.value;
            if (this.value === "true") {
                tip = "关闭";
                datas.IsShow = false;
            }
            else {
                datas.IsShow = true;
            }
            $.ajax({
                url: "/Menu/SelectMenu?Id="+this.id,
                type: "post",
                success: function (result) {
                    datas.ModuleId = result.ModuleId;
                    datas.ParentId = result.ParentId;
                    datas.Name = result.Name;
                    datas.Url = result.Url;
                    datas.Icon = result.Icon;
                    datas.SortId = result.SortId;
                    datas.CreateUserId = result.CreateUserId;
                    datas.CreateTime =Format(result.CreateTime, 'yyyy-MM-dd hh:mm:ss');
                }
            })
            layer.confirm(tip + '显示吗', function (index) {
                $.ajax({
                    url: "/Menu/GetUpdateMenuIsShow",
                    data: datas,
                    type: "Post",
                    success: function (data) {
                        if (data.Success) {
                            layer.msg(tip + '成功！', {
                                title: '提示框',
                                icon: 1,
                                time: 2000
                            });
                            location.reload();//刷新页面
                        }
                        else {
                            layer.msg(tip + '失败！', {
                                title: '提示框',
                                icon: 1,
                                time: 2000
                            });
                        }
                    }
                });
            });
        })
       
        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            var ID = data.Id;
            if (obj.event === 'del') {
                //判断户名称是否为空则进行删除
                var menu = {};
                menu.Id = ID;   
                $.ajax({
                    url: "/Menu/DelMenuId",
                    type: "post",
                    data: menu,
                    success: function (result) {
                        if (result.Success) {
                            layer.msg("修改成功", { icon: 1, time: 2500, title: "提示" });
                            location.reload();//刷新页面
                        }
                        else {
                            layer.msg("修改失败", { icon: 0, time: 2500, title: "提示" });
                        }
                    }
                })
            } else if (obj.event === 'edit') {
                //查询数据
                 Empty();
                Assignment(data);
                layer.open({
                    type: 1,
                    title: '修改菜单',
                    maxmin: true,
                    shadeClose: false,
                    area: ['800px', ''],
                    content: $('#Competence_add_style'),
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        var num = 0;
                        var str = "";
                        $(".col-sm-9 input[type$='text'],#form_textarea").each(function (n) {
                            if ($(this).val() == "") {
                                layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                                    title: '提示框',
                                    icon: 0,
                                });
                                num++;
                                return false;
                            }
                        });
                        if (num > 0) { return false; }
                        else {
                            //添加
                            var menu = {};
                            menu.ModuleId = $("#ModuleId").val();
                            menu.ParentId = $("#ParentId").val();
                            menu.Name = $("#Name").val();
                            menu.Url = $("#Url").val();
                            menu.IsShow = $("#IsShow").val();
                            menu.Icon = $("#Icon").val();
                            menu.SortId = $("#SortId").val();
                            menu.CreateUserId = $("#CreateUserId").val();
                            menu.CreateTime = $("#CreateTime").val();
                            menu.Id= $("#ID").val();
                            $.ajax({
                                url: "/Menu/AddingInformation",
                                type: "post",
                                data: menu,
                                success: function (result) {
                                    if (result.Success) {
                                        layer.msg("修改成功", { icon: 1, time: 2500, title: "提示" });
                                        location.reload();//刷新页面
                                    }
                                    else {
                                        layer.msg("修改失败", { icon: 0, time: 2500, title: "提示" });
                                    }
                                }
                            })
                        }
                    }
                });
            }
         });
    });

</script>
<script type="text/javascript">
    /*添加权限*/
    $('#Competence_add').on('click', function () {
        Empty();
        layer.open({
            type: 1,
            title: '添加菜单',
            maxmin: true,
            shadeClose: false,
            area: ['800px', ''],
            content: $('#Competence_add_style'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $(".col-sm-9 input[type$='text'],#form_textarea").each(function (n) {
                    if ($(this).val() == "") {
                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        });
                        num++;
                        return false;
                    }
                });
                if (num > 0) { return false; }
                else {
                    //添加
                    var menu = {};
                    menu.ModuleId = $("#ModuleId").val();
                    menu.ParentId = $("#ParentId").val();
                    menu.Name = $("#Name").val();
                    menu.Url = $("#Url").val();
                    menu.IsShow = $("#IsShow").val();
                    menu.Icon = $("#Icon").val();
                    menu.SortId = $("#SortId").val();
                    menu.CreateUserId = $("#CreateUserId").val();
                    menu.CreateTime = $("#CreateTime").val();
                    if (menu.Name != null) {
                        $.ajax({
                            url: "/Menu/SelectMenuName?name=" + menu.Name,
                            type: "post",
                            success: function (result) {
                                if (result.Success) {
                                    layer.msg("已存在" + menu.Name, { icon: 0, time: 2500, title: "提示" });
                                }
                                else {
                                    $.ajax({
                                        url: "/Menu/AddingInformation",
                                        type: "post",
                                        data: menu,
                                        success: function (result) {
                                            if (result.Success) {
                                                layer.msg("添加成功", { icon: 1, time: 2500, title: "提示" });
                                                location.reload();//刷新页面
                                            }
                                            else {
                                                layer.msg("添加失败", { icon: 0, time: 2500, title: "提示" });
                                            }
                                        }
                                    })
                                }
                            }
                        })
                    }
                }
            }
        });
    });
    /*权限-删除*/
    function Competence_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $(obj).parents("tr").remove();
            layer.msg('已删除!', { icon: 1, time: 1000 });
        });
    }
    /*修改权限*/
    function Competence_modify(id) {
        window.location.href = "Competence.html?=" + id;
    };
    /*字数限制*/
    function checkLength(which) {
        var maxChars = 200; //
        if (which.value.length > maxChars) {
            layer.open({
                icon: 2,
                title: '提示框',
                content: '您出入的字数超多限制!',
            });
            // 超过限制的字数了就将 文本框中的内容按规定的字数 截取
            which.value = which.value.substring(0, maxChars);
            return false;
        } else {
            var curr = maxChars - which.value.length; //250 减去 当前输入的
            document.getElementById("sy").innerHTML = curr.toString();
            return true;
        }
    };
    //面包屑返回值
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.iframeAuto(index);
    $('.Order_form ,#Competence_add').on('click', function () {
        var cname = $(this).attr("title");
        var cnames = parent.$('.Current_page').html();
        var herf = parent.$("#iframe").attr("src");
        parent.$('#parentIframe span').html(cname);
        parent.$('#parentIframe').css("display", "inline-block");
        parent.$('.Current_page').attr("name", herf).css({ "color": "#4c8fbd", "cursor": "pointer" });
        //parent.$('.Current_page').html("<a href='javascript:void(0)' name="+herf+">" + cnames + "</a>");
        parent.layer.close(index);

    });
    //赋值
    function Assignment(menu) {
        $("#ModuleId").val(menu.ModuleId);
        $("#ParentId").val(menu.ParentId);
        $("#Name").val(menu.Name);
        $("#Url").val(menu.Url);
        $("#Icon").val(menu.Icon);
        $("#SortId").val(menu.SortId);
        $("#CreateUserId").val(menu.CreateUserId);
        $("#CreateTime").val(Format(menu.CreateTime, 'yyyy-MM-dd hh:mm:ss'));
        $("#ID").val(menu.Id);
        var sel = document.getElementById("CreateTime");
        if (menu.IsShow == false) {
            sel.selectedIndex = 0;
        } else {
            sel.selectedIndex = 1;
        }
    }
    //清空
    function Empty() {
        $("#ModuleId").val("");
        $("#ParentId").val("");
        $("#Name").val("");
        $("#Url").val("");
        $("#IsShow").val("0");
        $("#Icon").val("");
        $("#SortId").val("");
        $("#CreateUserId").val("");
        $("#CreateTime").val("");
        $("#Id").val("");
    }
</script>